namespace KinonekoSoftware.Extensions.Reflections
{
    public sealed class EnumValuesFilteringFactory<T> where T : struct, Enum
    {
        private readonly Lazy<IEnumerable<T>> _factory ;

        public EnumValuesFilteringFactory(Predicate<T> filter)
        {
            var predicate  = filter ?? throw new ArgumentNullException(nameof(filter));
            _factory = new Lazy<IEnumerable<T>>(() => ClassStatic.GetEnums<T>().Where(x => predicate(x)));
        }

        /// <summary>
        /// 获取枚举的所有字段。
        /// </summary>
        public IEnumerable<T> Values => _factory.Value;
    }
}